using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for BasePostPage
/// </summary>
public abstract class BasePostPage : BasePage
{
    protected override void OnLoad(EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                postId = int.Parse(Request.QueryString["Id"]);
            }
            catch (FormatException)
            {
            }
            catch (ArgumentNullException)
            {
            }
        }
        base.OnLoad(e);
    }

    private int postId;
    public int PostId
    {
        get { return postId; }
    }

    private Acms.Bll.Post currentPost;
    public Acms.Bll.Post CurrentPost
    {
        get
        {
            if (currentPost == null && postId > 0)
            {
                currentPost = Acms.Bll.Post.GetById(postId);
            }
            return currentPost;
        }
    }

    protected override object SaveViewState()
    {
        ViewState["PostId"] = postId;
        return base.SaveViewState();
    }

    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        if (ViewState["PostId"] is int)
        {
            postId = (int)ViewState["PostId"];
        }
    }
}
